<?php
function sql_query($sql) {
    $temp = mysql_query($sql) or die("Mysql Syntax Error:<br> Query: <b>$sql</b><br>".mysql_error());
    return $temp;
}
function sql_fetch_row($temp) {
    $res = mysql_fetch_array($temp);
    return $res;
}
function format_url($input) {
    $input=trim($input);
    $find = array("/[^a-zA-Z0-9\s]/","/\s+/");
    $replace = array("","-");
    $return = strtolower(preg_replace($find, $replace, $input));
    return $return;
}
function paging($url, $total, $page=1, $indexon=6, $perpage=10, $lasting=false) {
    $return = "";
    if(($page-$indexon)>1 and $lasting) {
        $return .= " <a href=\"$url"."1\">[ First ]</a> ... ";
    }
    for($i=($page-$indexon);$i<=($page+$indexon);$i++) {
        if($page==$i) {
            $return .= " [Page $i] ";
        } else if($i<1) {
                $return .= "";
            } else if((($i-1)*$perpage)>$total) {
                    $return .= "";
                } else {
                    $return .= " <a href=\"$url"."$i\">[$i]</a> ";
                }
    }
    if((($page+$indexon)*$perpage)<$total and $lasting) {
        $return .= " ... <a href=\"$url".ceil($total/$perpage)."\">[ Last ]</a> ";
    }
    $return .= "";
    return $return;
}
?>